package com.baoai.common;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by xiaren on 2016/10/20.
 */
public class BeanFactory implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;

    public BeanFactory() {
    }

    public void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }

    public static Object getBean(String beanName) {
        return applicationContext.containsBean(beanName)?applicationContext.getBean(beanName):null;
    }

    public static Object getBean(String beanName, String defaultBeanName) {
        Object obj = getBean(beanName);
        if(obj == null) {
            obj = getBean(defaultBeanName);
        }
        return obj;
    }
}
